
myApp.controller('AfterServiceDetailController',function($scope,toaster,$serAfterService,$stateParams,$uibModal,$filter,$state,$log){
    var ctrl = this;
    ctrl.vm = {
        data:{},
        id:$stateParams.id,
        flag:0,
        pass:function(id){  //通过
            $serAfterService.setApproved({
                id:id,
                comment:ctrl.vm.data.comment1
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data.status=2
                    vm.init();
                    toaster.info('提示',res.message);
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
        reject:function(id){  //驳回
            $serAfterService.setRejected({
                id:id,
                comment:ctrl.vm.data.comment1
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data.status=4
                    vm.init();
                    toaster.info('提示',res.message);
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
        receive:function(id){  //收货
            $serAfterService.setRecevied({
                id:id,
                comment:ctrl.vm.data.comment2
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data.status=3
                    vm.init();
                    toaster.info('提示',res.message);
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
        over:function(id){  //结束
            if(ctrl.vm.flag==1){
                $serAfterService.setDone({
                    id:id,
                    comment:ctrl.vm.data.comment3
                }).then(function(res){
                    if(res.code==1){
                        ctrl.vm.data.status=3
                        vm.init();
                        toaster.info('提示',res.message);
                    }else{
                        toaster.info('提示',res.message);
                    }
                })
            }else{
                toaster.info('提示','请先完成退款');
            }

        },
        refund:function(id){  //退款
            $serAfterService.refund({
                id:id,
                refund:ctrl.vm.data.refund,
                comment:ctrl.vm.data.comment6
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data.refund='';
                    ctrl.vm.flag=1;
                    vm.init();
                    toaster.info('提示',res.message);
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
        remark:function(id){  //添加备注
            $serAfterService.addCommnt({
                id:id,
                comment:ctrl.vm.data.comment5
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data.comment5='';
                    vm.init();
                    toaster.info('提示',res.message);
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
        renew:function(id){  //恢复库存
            $serAfterService.backStock({
                id:id,
                comment:ctrl.vm.data.comment4,
                num:ctrl.vm.data.num
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data.comment4='';
                    ctrl.vm.data.num=''
                    vm.init();
                    toaster.info('提示',res.message);
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },

    };
    $scope.vm={
        page:{}
    };
    /*跳转页面*/
    $scope.pageChanged = function() {
        vm.init($scope.vm.page.current_page)
    };
    /*每页显示数量显示*/
    $scope.placement = {
        options: [5,10,20,50],
        pageSize:5,
        selected: 20,
        changeFn:function(){
            vm.init(0)
        }
    };

    var vm ={
        init:function(){
            $serAfterService.getIt({
               id:$stateParams.id
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data = res.data;
                    $scope.vm.page = res.addtion_data;
                }else{
                    ctrl.vm.data ="";
                    toaster.info('提示',res.message);
                }
            })
        }
    };
    vm.init();
});

